package com.huluobo.a2212mdmdemo.demo

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.staggeredgrid.LazyHorizontalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Face
import androidx.compose.material3.Button
import androidx.compose.material3.Divider
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedIconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage

/**
 *  Created by LC on 2025/5/22.
 */
@Composable
fun MyButton() {
    Column(Modifier.padding(20.dp), verticalArrangement = Arrangement.spacedBy(20.dp)) {
        Button(onClick = {
            Log.i("TagA", "点击了登录")
        }, modifier = Modifier.fillMaxWidth()) {
            Column {
                Text(text = "登录")
                Icon(imageVector = Icons.Default.Face, contentDescription = "")
            }
        }

        OutlinedButton(onClick = { /*TODO*/ }) {
            Text(text = "OutlinedButton")
        }

        ElevatedButton(onClick = {}) {
            Text(text = "ElevatedButton")
        }

        TextButton(onClick = {}) {
            Text(text = "TextButton")
        }

        OutlinedIconButton(onClick = {}) {
            Text(text = "OutlinedIconButton")
        }
    }
}

@Composable
fun MyBox() {
    Box(modifier = Modifier.padding(10.dp), contentAlignment = Alignment.TopEnd) {
        Text(
            text = "hello", modifier = Modifier
                .background(Color.Yellow, RoundedCornerShape(10.dp))
                .border(1.dp, Color.Blue, RoundedCornerShape(10.dp))
                .padding(10.dp, 5.dp)
        )
        Text(
            text = "1",
            color = Color.White,
            textAlign = TextAlign.Center,
            fontSize = 8.sp,
            modifier = Modifier
                .size(16.dp)
                .offset(3.dp, (-3).dp)
                .background(Color.Red, CircleShape)
                .padding(3.dp)
        )
    }
}

data class Student(val name: String, val desc: String, val img: String)

@Composable
fun MyList() {
    val list = mutableListOf<Student>()

    for (i in 1..20) {
        list.add(
            Student(
                "张三$i",
                "这是我的个人简介:$i",
                "https://img1.baidu.com/it/u=4214113141,2036563917&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1729098000&t=0662d2b383091882ccdd43ad060de2a7",
            )
        )
    }

    //纵向列表
//    LazyColumn(content = {
//        items(list) {
//            StudentItem(student = it)
//        }
//    })
    //纵向网格
//    LazyVerticalGrid(columns = GridCells.Fixed(3), content = {
//        items(list) {
//            StudentItem(student = it)
//        }
//    })

    //横向瀑布流列表
    LazyHorizontalStaggeredGrid(rows = StaggeredGridCells.Fixed(3), content = {
        items(list) {
            StudentItem(student = it)
        }
    })


}

//相当于RecyclerView中的item
@Composable
fun StudentItem(student: Student) {
    Column(Modifier.padding(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
        Row {
            AsyncImage(
                model = student.img,
                contentDescription = "",
                contentScale = ContentScale.Crop,
                modifier = Modifier
                    .size(80.dp)
                    .clip(
                        CircleShape
                    )
            )
            //间隔,相当于给了一个10dp的空格
            Spacer(modifier = Modifier.width(10.dp))
            Column(Modifier.height(80.dp), verticalArrangement = Arrangement.SpaceAround) {
                Text(text = student.name)
                Text(text = student.desc)
            }
        }
        Spacer(modifier = Modifier.height(10.dp))
        Divider()
    }
}
